home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / DS-1.ZIP;1 / CONFIG.ZIP / RSWITCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-02-10  |  2.9 KB  |  104 lines

  1. ;
  2. ;   Coswitch for Icon V8 interpreter running in 32 bit protected mode
  3. ;   with MetaWare High C 386 (PharLap DOS|Extender) or Intel 386/486
  4. ;   C Code Builder Kit.
  5. ;
  6. ;   Author:  Robert Goldberg
  7. ;
  8. ;   Note: Assemble with PharLap assembler and -twocase switch to
  9. ;   preserve lower-case public names (important for Intel linker).
  10. ;
  11. ;   Coswitch algorithm in C:
  12. ;
  13. ;   coswitch( old_cs, new_cs, first )
  14. ;   int    *old_cs, *new_cs, first;
  15. ;   {
  16. ;    /* save SP, frame pointers, and other registers in old_cs */
  17. ;    if ( first == 0 )
  18. ;    {
  19. ;        /* load sp from new_sp[0] and clear frame pointers */
  20. ;        interp( 0, 0 );
  21. ;        syserr( "interp() returned in coswitch" );
  22. ;    }
  23. ;    else
  24. ;    {
  25. ;        /* load sp, frame pointers and other registers from new_cs */
  26. ;    }
  27. ;   }
  28. ;
  29. ;   Define external functions:
  30. ;
  31.     .386
  32.     extrn    interp:near
  33.     extrn    runerr:near
  34. ;
  35. ;   Define error message in appropriate segment and group.
  36. ;
  37. dgroup    group    asmdata
  38.     assume    ds:dgroup
  39.     public    errormsg
  40. asmdata    segment    dword public 'DATA'
  41. errormsg db    'interp() returned in coswitch',0
  42. asmdata    ends
  43. ;
  44. ;   Define function coswitch in appropriate segment and group.
  45. ;
  46. cgroup    group    asmcode
  47.     assume    cs:cgroup
  48. asmcode    segment    dword 'CODE'
  49.     public    coswitch
  50.     db    'coswitch',8
  51. coswitch    proc    near
  52. ;
  53. ;   Save environment at point of call.
  54. ;
  55. ;   According to MetaWare's documentation (Chapter 9 - Run-Time Organization)
  56. ;   registers EAX, ECX, EDX, FS, GS, and sometimes ES are volatile.  So, a
  57. ;   function must preserve registers EBP, ESI, EDI, and EBX across calls.
  58. ;   So, save all these registers plus ESP in area pointed to by old_cs.
  59. ;
  60.     mov    edx,4[esp]        ; point to old_cs
  61.     mov    0[edx],esp        ; save esp
  62.     mov    4[edx],ebp        ; save ebp
  63.     mov    8[edx],esi        ; save esi
  64.     mov    12[edx],edi        ; save edi
  65.     mov    16[edx],ebx        ; save ebx
  66. ;
  67. ;   Check first flag to see if first activation of this coexpression.
  68. ;
  69.     mov    eax,12[esp]        ; load first flag
  70.     or    eax,eax            ; set condition flags
  71.     jnz    notzero            ; jump if not zero
  72. ;
  73. ;   First is 0 -
  74. ;
  75. ;   Set things up for first activation of this coexpression.
  76. ;
  77.     mov    edx,8[esp]        ; point to new_cs area
  78.     mov    esp,0[edx]        ; set ESP from new_cs
  79.     mov    ebp,esp            ; set EBP equal to ESP (can't hurt?)
  80.     xor    eax,eax            ; get a zero
  81.     mov    esi,eax            ; clear ESI
  82.     mov    edi,eax            ; clear EDI
  83.     push    eax            ; push two zeros
  84.     push    eax            ;   onto stack
  85.     call    interp            ; interp(0,0) - should not return!
  86.     push    offset errormsg        ; push offset to error messgae
  87.     call    runerr            ; terminate with error
  88. ;
  89. ;   First is not 0 -
  90. ;
  91. ;   Restore environment from new_cs.
  92. ;
  93. notzero:
  94.     mov    edx,8[esp]        ; point to new_cs
  95.     mov    esp,0[edx]        ; restore esp
  96.     mov    ebp,4[edx]        ; restore ebp
  97.     mov    esi,8[edx]        ; restore esi
  98.     mov    edi,12[edx]        ; restore edi
  99.     mov    ebx,16[edx]        ; restore ebx
  100.     ret                ; return
  101. coswitch    endp
  102. asmcode    ends
  103.     end
  104.